    // Wait for device API libraries to load
    //

    var SDK = function (window, document) {


        var DefineProperty = function (obj, name, value) {
            Object.defineProperty(obj, name, {
                get: function () {
                    return value;
                }
            })
        };
        var Random = function (len) {
            len = len || 32;

            var $chars = 'ABCDEFGHJKMNPQRSTWXYZ1234567890';
            var maxPos = $chars.length;
            var pwd = '';
            for (var i = 0; i < len; i++) {
                pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
            }
            return pwd;
        };
        
        window.jssdk = {};

        var arFor = function (obj, end) {
            end = end == null ? function () {} : end;
            var off = typeof (obj) == "object" && obj.length > -1;
            var ar = [];
            if (off) {
                ar = obj;
            } else {
                for (var key in obj) {
                    ar.push(key);
                }
            }
            var forEach = function (func, index) {
                index = index == null ? -1 : index;
                index = index + 1;
                if (ar.length <= index) {
                    end(index, (off ? null : ar[index - 1]));
                } else {
                    func(obj[(off ? index : ar[index])], function () {
                        forEach(func, index++);
                    }, (off ? null : ar[index]));
                }
            };
            this.forEach = forEach;
        };

        var UploadSys = function (CordovaSdk) {
            CordovaSdk.ChcpUpdate()
        };

        var _initcordova = function (CordovaSdk) {

            var ImageBox = function (Callback) {
                var value = "yes";
                Image.prototype.CordovaCache = 'yes';
                Object.defineProperty(Image.prototype, "Src", {
                    get: function () {
                        return value;
                    },
                    set: function (val) {
                        Callback(this, val)
                        value = val;
                    }
                })
            };
            new ImageBox(function (img, val) {
                CordovaSdk.download({
                    uri: val,
                    savefile: val.replace("//", "/").replace(":", "")
                }, function (error, entry) {
                    if (entry != null) {
                        var targetURL = entry.toURL();
                        img.src = targetURL;
                    } else {
                        img.src = val;
                    }
                });
            });

            window.Alert = function (message, AlertCallback, title, buttonName) {
                message = message || '!';
                AlertCallback = AlertCallback || function () {};
                title = title || 'Alert';
                buttonName = buttonName || 'Ok';
                navigator.notification.alert(message, AlertCallback, title, buttonName)
            };

            window.Confirm = function (message, confirmCallback, title, buttonLabels) {
                message = message || '!';
                confirmCallback = confirmCallback || function () {};
                title = title || 'Confirm';
                buttonLabels = buttonLabels || ['Ok', 'No'];
                navigator.notification.confirm(message, confirmCallback, title, buttonName)
            };
            CordovaSdk.console = function (off) {
                if (!off) {
                    return;
                }
                console.log = function (obj, orun) {

                    var val = obj;
                    if (typeof obj == "object") {
                        val = JSON.stringify(obj);
                    };
                    axios.post("http://cordova.nodewebos.com/cordova-console-log/", {
                            log: val,
                            lastName: 'axios'
                        })
                        .then(function (response) {
                            //console.log(response);
                        })
                        .catch(function (error) {
                            //console.log(error);
                        });
                    return;
                    $.ajax({
                        //请求方式
                        type: "POST",
                        //请求地址
                        url: "http://cordova.nodewebos.com/cordova-console-log/",
                        //数据，json字符串
                        data: val,
                        //请求成功
                        success: function (result) {
                            //console.log(result);
                        },
                        //请求失败，包含具体的错误信息
                        error: function (e) {
                            //console.log(e.status);
                            // console.log(e.responseText);
                        }
                    });


                    return



                }
            }
        }

        var _chcp = function (CordovaSdk) {
            var geterrorname = function (id) {
                for (var key in chcp.error) {
                    if (chcp.error[key] == id) {
                        return key
                    }
                }
                return null;
            }
            if (window.chcp) {
                var showAlert = function (str) {

                    Alert(str, function () {


                    }, '提示', '确定')
                }
                var confirmCallback = function (index) {
                    switch (index) {
                        case 2:
                            chcp.installUpdate(function (installError) {
                                if (installError != null) {
                                    Alert(geterrorname(installError.code))
                                } else {
                                    alert('安装更新完成...', function () {

                                    }, "Alert", "ok");
                                }
                            });
                            break;
                        default:
                            console.log("取消安装更新...");
                            break;
                    }
                };

                var UploadSys = function (off) {
                    chcp.fetchUpdate(function (fetchError, data) {
                        if (!fetchError) {
                            if (off) {
                                var ls = ['取消', '确定'];
                                navigator.notification.confirm('更新已经下载完毕，确认安装更新?', confirmCallback, '更新提示', ls);
                            } else {
                                chcp.installUpdate(function (installError) {
                                    if (installError != null) {
                                        console.log('安装更新失败...' + JSON.stringify(installError));
                                    } else {
                                        console.log('安装更新完成...');
                                    }
                                });
                            }
                        } else {
                            if (off) {
                                if (fetchError.code != null) {
                                    Alert(geterrorname(fetchError.code))
                                }
                            } else {
                                console.log(fetchError);
                            }
                        }
                    });
                }
                CordovaSdk.UploadSys = UploadSys;

            }
        }
        var _Events = function (CordovaSdk) {

            document.addEventListener("deviceready", function () {
                //设备就绪
            }, false);
            document.addEventListener("pause", function () {
                //暂停

            }, false);

            document.addEventListener("resume", function () {
                //恢复
            }, false);
            document.addEventListener("online", function () {
                //线上
            }, false);

            document.addEventListener("offline", function () {
                //离线
            }, false);

            document.addEventListener("backbutton", function () {
                //返回键
            }, false);

            document.addEventListener("batterycritical", function () {
                //电池严重不足
            }, false);

            document.addEventListener("batterylow", function () {
                //电量不足
            }, false);

            document.addEventListener("batterystatus", function () {
                //电池状态
            }, false);

            document.addEventListener("menubutton", function () {
                //菜单按钮
            }, false);

            document.addEventListener("searchbutton", function () {
                //搜索按钮
            }, false);

            document.addEventListener("searchbutton", function () {
                //开始通话按钮
            }, false);

            document.addEventListener("startcallbutton", function () {
                //开始通话按钮
            }, false);

            document.addEventListener("endcallbutton", function () {
                //呼叫按钮
            }, false);

            document.addEventListener("volumedownbutton", function () {
                //音量下调按钮
            }, false);

            document.addEventListener("volumeupbutton", function () {
                //音量上调按钮
            }, false);

        }
        var _webapp = function (CordovaSdk) {
            var interval = 100;
            var downloadapplist = function (package, Callback, setprogress) {
                var ErrorList = [];
                var manifest = package.manifest;
                var content_url = package.content_url;
                var len = manifest.length;
                var index = 0;
                new arFor(manifest, function () {
                    Callback(ErrorList.length == 0 ? null : ErrorList, package);
                }).forEach(function (item, next) {
                    var uri = content_url + item.file;
                    var locationfile = uri.replace("//", "/").replace(":", "");
                    CordovaSdk.download({
                        uri: uri,
                        force: true,
                        savefile: locationfile
                    }, function (error, entry) {
                        if (error) {
                            ErrorList.push(item);
                        }
                        setTimeout(function () {
                            next();
                            index++;
                            setprogress(index / len);
                        }, interval)
                    })
                })
            }
            var downloadjson = function (uri, Callback, _savefile) {
                var locationfile = (_savefile == null ? uri.replace("//", "/").replace(":", "") : _savefile);

                CordovaSdk.download({
                    uri: uri,
                    savefile: locationfile
                }, function (error, entry, off_download) {
                    if (entry != null) {
                        var targetURL = entry.toURL();
                        CordovaSdk.OpenText(locationfile, function (error, ev) {
                            if (error == null) {
                                var chcp = JSON.parse(ev);
                                Callback(null, chcp, off_download == true)
                            } else {
                                Callback(error)
                            }
                        })
                    } else {
                        Callback(error)
                    }
                })
            };
            var openManifest = function (package, Callback) {
                var content_url = package.content_url;
                var uri = content_url + 'chcp.manifest';
                downloadjson(uri, function (error, manifest, NewDow) {
                    if (!error) {
                        if (NewDow) {
                            package.manifest = manifest;
                            Callback(null, package)
                            return;
                        } else {
                            var Manifest = []
                            downloadjson(uri,
                                function (new_error, new_manifest) {
                                    if (new_error == null) {
                                        for (var i = 0; i < new_manifest.length; i++) {
                                            var off = 1;
                                            for (var j = 0; j < manifest.length; j++) {
                                                if (manifest[j].file == new_manifest[i].file && manifest[j].hash != new_manifest[i].hash) {
                                                    off = 2;
                                                    manifest.splice(j, 1);
                                                    break;
                                                } else if (manifest[j].file == new_manifest[i].file && manifest[j].hash == new_manifest[i].hash) {
                                                    off = 0;
                                                    manifest.splice(j, 1);
                                                    break;
                                                }
                                            }
                                            if (off > 0) {
                                                Manifest.push(new_manifest[i]);
                                            }
                                        }
                                    }
                                    package.manifest = Manifest;
                                    Callback(null, package)
                                }, 'temp/' + Random(20) + '.js')
                        }
                    } else {
                        Callback(error, package)
                    }
                })
            };
            var openapppackage = function (url, Callback, progress) {

                downloadjson(url, function (error, package, NewDow) {
                    var Updated = function (package) {

                        openManifest(package, function (error, package) {
                            downloadapplist(package, function (errorlist) {
                                if (errorlist == null) {
                                    Callback(null, package)
                                } else {
                                    Callback(errorlist, package)
                                }
                            }, progress)
                        })
                    }
                    if (error) {
                        return;
                    } else if (NewDow == true) {
                        package._newinstall = true;
                        Updated(package)
                    } else {
                        package._newinstall = false;
                        downloadjson(url, function (new_error, val) {
                            if (new_error) {
                                Updated(package)
                            } else if (package.release == val.release) {
                                Callback(null, package)
                            } else {
                                var savepackage = url.replace("//", "/").replace(":", "");
                                package = val;

                                CordovaSdk.SaveFile(savepackage, JSON.stringify(val), function (error, val) {

                                    package._newinstall = false;

                                    Updated(package)
                                })
                            }
                        }, 'temp/' + Random(20) + '.js');
                    }
                })
            }
            CordovaSdk.appinstall = function (appUri, Callback, progress) {
                openapppackage(appUri, function (error, package) {
                    Callback(package)
                }, progress)
            }
            CordovaSdk.openApp = function (appUri, Callback) {

                Callback = (Callback == null ? function () {} : Callback);

                var newinstall = true;

                var inapp = CordovaSdk.inappbrowser(dirname(window.location.href) + '/load.html');

                var setprogress = function (val) {
                    if (inapp == null) {
                        return
                    }
                    inapp.executeScript({
                        code: 'progressbar.style.width="' + (val * 100) + '%";'
                    });
                }
                var openinapp = function (package) {
                    var url = package.home;
                    url = url.replace("//", "/").replace(":", "");
                    CordovaSdk.FileInfo(url, function (entry) {
                        if (entry != null) {
                            var targetURL = entry.toURL();
                            if (newinstall == true) {
                                inapp.executeScript({
                                    code: 'progressbar.style.width="100%";'
                                });
                            }
                            setTimeout(function (params) {
                                inapp.executeScript({
                                    code: 'window.location.href="' + targetURL + '";'
                                });
                            }, newinstall ? interval : 0)
                            //CordovaSdk.inappbrowser(targetURL);
                        } else {


                        }
                    })
                };
                openapppackage(appUri, function (error, package) {
                    package.home = package.content_url + 'index.html';
                    newinstall = package._newinstall;
                    openinapp(package)
                }, setprogress)
            };
        };

        var _file = function (CordovaSdk) {
            var _RequestFileSystem = function (Callback) {
                window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
                    Callback(null, fileSystem.root);
                }, function (error) {
                    Callback(error, null);
                })
            };
            var dirname = function (file) {
                var fs = file.split("/");
                fs.pop();
                return fs.join('/');
            };

            var readDataUrl = function (file, Callback) {
                var reader = new FileReader();
                reader.onloadend = function (evt) {
                    Callback(evt.target.result, file);
                };
                reader.readAsDataURL(file);
            };

            function readAsText(file, Callback) {
                var reader = new FileReader();
                reader.onloadend = function (evt) {
                    Callback(evt.target.result, file);
                };
                reader.readAsText(file);
            };
            var openjson = function (file, Callback) {

                readAsText(file, function (str) {

                    Callback(JSON.parse(str))
                })
            }
            var mkdir = function (fs, file, Callback) {
                fs.getDirectory(file, null, function (a) {
                    Callback(file)
                }, function () {
                    fs.getDirectory(file, {
                        create: !0
                    });
                    Callback(file)
                });
            };

            var mkdirs = function (file, Callback, fs) {
                var run = function (fs) {
                    var temfile = null;
                    var arlist = file.split('/');
                    new arFor(arlist, function () {
                        Callback(null, null);
                    }).forEach(function (item, next) {
                        if (temfile == null) {
                            temfile = item;
                        } else {
                            temfile = temfile + '/' + item;
                        };
                        mkdir(fs, temfile, function (entry) {
                            next()
                        })
                    })
                }
                if (fs != null) {
                    run(fs);
                } else {

                    _RequestFileSystem(function (error, fs) {

                        if (error == null) {

                            run(fs);

                        } else {

                            Callback(error)
                        }

                    })
                }
            };
            var LocalFile = function (file, Callback, fs) {
                ValidOrNot(file, Callback, fs)
            };

            CordovaSdk.LocalFile = LocalFile;

            CordovaSdk.OpenDataUrl = function (file, Callback) {

                var run = function (fs) {
                    fs.getFile(file, null, gotFileEntry, fail);
                }
                var gotFileEntry = function (fileEntry) {
                    fileEntry.file(gotFile, fail);
                }
                var gotFile = function (file) {
                    readDataUrl(file, function (evt, file) {
                        Callback(evt, file);
                    });
                }

                function fail(evt) {
                    console.log(evt.target.error.code);
                    Callback(evt, null);
                }
                _RequestFileSystem(function (error, fs) {
                    if (error == null) {
                        run(fs)
                    } else {
                        fail(error)
                    }
                })
            };

            CordovaSdk.OpenText = function (file, Callback) {

                var run = function (fs) {
                    fs.getFile(file, null, gotFileEntry, fail);
                }
                var gotFileEntry = function (fileEntry) {
                    fileEntry.file(gotFile, fail);
                }
                var gotFile = function (file) {
                    readAsText(file, function (evt) {
                        Callback(null, evt);
                    });
                };

                function fail(evt) {
                    Callback(evt.target.error, null);
                };

                _RequestFileSystem(function (error, fs) {
                    if (error == null) {
                        run(fs)
                    } else {
                        fail(error)
                    }
                });

            };
            CordovaSdk.SaveFile = function (file, value, Callback, fs) {
                var save = function (fs) {
                    mkdirs(dirname(file), function () {
                        fs.getFile(file, {
                            create: true,
                            exclusive: false
                        }, gotFileEntry, fail)
                    }, fs)
                }

                function gotFileEntry(fileEntry) {
                    fileEntry.createWriter(gotFileWriter, fail);
                }

                function gotFileWriter(writer) {
                    writer.onwriteend = function (evt) {
                        Callback(null, evt);
                    };
                    writer.write(value);
                }

                function fail(error) {
                    Callback(error);
                }
                if (fs == null) {
                    _RequestFileSystem(function (error, fs) {
                        if (error == null) {
                            save(fs)
                        } else {
                            fail(error)
                        }
                    })
                } else {
                    save(fs);
                }
            };
            CordovaSdk.Camera = function (options, Callback) {
                navigator.camera.getPicture(function (localfile) {
                    Callback(null, localfile)
                }, Callback, options);
            }
            CordovaSdk.UploadFile = function (url, localfile, options, Callback) {
                var _Options = new FileUploadOptions();
                for (var key in options) {
                    _Options[key] = options[key];
                };
                var ft = new FileTransfer();
                ft.upload(localfile, url,
                    function (result) {
                        Callback(null, result)
                    },
                    function (error) {
                        Callback(error)
                    }, _Options);
            };
            CordovaSdk.UploadImage = function (options, Callback) {
                var CameraOptions = {
                    destinationType: 1,
                    sourceType: 2,
                    quality: 80,
                    mediaType: 0,
                    allowEdit: true,
                    targetHeight: 512,
                    targetWidth: 512,
                    correctOrientation: true
                };
                var Camera = options.Camera;
                for (var key in Camera) {
                    CameraOptions[key] = Camera[key];
                };

                CordovaSdk.Camera(CameraOptions, function (error, localfile) {
                    if (error) {
                        Callback(error)
                    } else {
                        CordovaSdk.UploadFile(options.url, localfile, options.Upload, function (error, val) {
                            Callback(error, val)
                        })
                    }
                })
            }
            CordovaSdk.UploadImages = function (options, Callback) {

                function captureSuccess(mediaFiles) {
                    new arFor(mediaFiles, function () {
                        Callback(null, {})
                    }).forEach(function (mediaFile, next) {
                        var Upload = options.Upload;
                        Upload.name = mediaFile.name;
                        CordovaSdk.UploadFile(options.url, mediaFile.fullPath, Upload, function (error, val) {
                            next();
                        })
                    })
                };
                navigator.device.capture.captureImage(captureSuccess, Callback, {
                    limit: options.limit
                });
            };
            CordovaSdk.UploadVideos = function (options, Callback) {

                function captureSuccess(mediaFiles) {
                    new arFor(mediaFiles, function () {
                        Callback(null, {})
                    }).forEach(function (mediaFile, next) {
                        var Upload = options.Upload;
                        Upload.name = mediaFile.name;
                        CordovaSdk.UploadFile(options.url, mediaFile.fullPath, Upload, function (error, val) {
                            next();
                        })
                    })
                };
                navigator.device.capture.captureVideo(captureSuccess, captureError, {
                    limit: options.limit
                });
            };
            CordovaSdk.UploadAudios = function (options, Callback) {
                function captureSuccess(mediaFiles) {
                    new arFor(mediaFiles, function () {
                        Callback(null, {})
                    }).forEach(function (mediaFile, next) {
                        var Upload = options.Upload;
                        Upload.name = mediaFile.name;
                        CordovaSdk.UploadFile(options.url, mediaFile.fullPath, Upload, function (error, val) {
                            next();
                        })
                    })
                };
                navigator.device.capture.captureAudio(captureSuccess, captureError, {
                    limit: options.limit
                });
            };
            var ValidOrNot = function (file, Callback, fs) {
                var run = function (fs) {
                    fs.getFile(file, null, function (fileEntry) {
                        fileEntry.file(function (entry) {
                            if (entry.size > 0) {
                                Callback(true, fileEntry)
                            } else {
                                fileEntry.remove(function () {
                                    Callback(false)
                                }, function () {
                                    Callback(false)
                                })
                            }
                        })
                    }, function () {
                        Callback(false)
                    })
                }
                if (fs != null) {

                    run(fs);

                } else {

                    _RequestFileSystem(function (error, fs) {

                        if (error == null) {

                            run(fs);

                        } else {

                            Callback(false)
                        }

                    })
                }
            };
            CordovaSdk.FileInfo = function (file, Callback, fs) {
                var run = function (fs) {
                    fs.getFile(file, null, function (fileEntry) {
                        fileEntry.file(function (entry) {
                            if (entry.size > 0) {
                                Callback(fileEntry, entry)
                            } else {
                                fileEntry.remove(function () {
                                    Callback(fileEntry)
                                }, function () {
                                    Callback(fileEntry)
                                })
                            }
                        })
                    }, function () {
                        Callback(null)
                    })
                }
                if (fs != null) {

                    run(fs);

                } else {

                    _RequestFileSystem(function (error, fs) {

                        if (error == null) {

                            run(fs);

                        } else {

                            Callback(false)
                        }

                    })
                }
            }
            CordovaSdk.download = function (db, Callback) {
                var savefile = db.savefile;
                var _download = function (fileEntry) {
                    var fileURL = fileEntry.nativeURL;
                    var fileTransfer = new FileTransfer();
                    var uri = encodeURI(db.uri);

                    fileTransfer.onprogress = function (e) {
                        // console.log('当前进度：' + e.loaded / e.total);
                        if (db.progress) {
                            db.progress(e);
                        }
                    }
                    fileTransfer.download(
                        uri,
                        fileURL,
                        function (entry) {
                            Callback(null, entry, true)
                        },
                        function (error) {
                            Callback(error)
                        })
                };
                _RequestFileSystem(function (error, fs) {
                    if (error == null) {
                        ValidOrNot(savefile, function (off, entry) {
                            if (off && !db.force) {
                                Callback(null, entry)
                            } else {
                                var file = dirname(savefile);
                                mkdirs(file, function () {
                                    fs.getFile(savefile, {
                                        create: true,
                                        exclusive: false
                                    }, function (fileEntry) {
                                        _download(fileEntry)
                                    }, function (err) {
                                        Callback(err);
                                    });
                                }, fs)
                            }
                        }, fs)
                    } else {

                        Callback(error)
                    }
                })
            }

        }
        var _dialogs = function (CordovaSdk) {
            CordovaSdk.alert = function (message, AlertCallback, title, buttonName) {
                navigator.notification.alert(message, AlertCallback, title, buttonName);
            }
            CordovaSdk.confirm = function (message, confirmCallback, title, buttonLabels) {
                navigator.notification.confirm(message, confirmCallback, title, buttonLabels)
            }
            CordovaSdk.prompt = function (message, resultCallback, title, buttonLabels, defaultText) {
                navigator.notification.prompt(message, resultCallback, title, buttonLabels, defaultText);
            }
            CordovaSdk.vibrate = function (Interval) {
                navigator.notification.vibrate(Interval);
            }
            CordovaSdk.beep = function (Interval) {
                navigator.notification.beep(Interval);
            }

        }
        var _Device = function (CordovaSdk) {
            CordovaSdk.inappbrowser = function (url, target) {
                target = target == null ? "_blank" : target;

                 
                var options = [
                    'closebuttoncaption=◉', //⦿◉
                    'hidenavigationbuttons=yes'
                ];
                var android = [
                    'zoom=no',
                    'hidden=yes',
                    'hideurlbar=yes',
                    'closebuttoncolor=#3a8adf',
                    'toolbartranslucent=yes',
                    'toolbarcolor=#454545'

                ];
                var ios = [
                    'lefttoright=yes',
                    'location=no',
                    'toolbartranslucent=yes',
                    'toolbarposition=top',
                    'enableViewportScale=yes',
                    'transitionstyle=coververtical' ///fliphorizontal，crossdissolve,coververtical
                ]
                if (cordova.platformId == 'ios') {
                    options = options.concat(ios)
                } else {
                    options = options.concat(android)
                }


                var inAppBrowserRef = cordova.InAppBrowser.open(url, target, options.join(','));




                inAppBrowserRef.show();
                return inAppBrowserRef
            }
            CordovaSdk.Scanner = function (Callback) {
                cordova.plugins.barcodeScanner.scan(
                    function (result) {
                        Callback(null, result);
                    },
                    function (error) {
                        Callback(error, null);
                    }
                );
            }

            CordovaSdk.ChcpUpdate = function (Callback) {
                if (window.chcp != null) {
                    chcp.fetchUpdate(function (error, data) {
                        if (!error) {
                            chcp.installUpdate(function (error) {
                                Callback(error)
                            });
                        } else {
                            Callback(error)
                        }
                    })
                }
            };
            CordovaSdk.ScannerCode = function (str, Callback) {

                cordova.plugins.barcodeScanner.encode(BarcodeScanner.Encode.TEXT_TYPE, str, function (success) {
                    Alert("encode success: " + success);
                    Callback(null, success)
                }, function (fail) {
                    Callback(fail, null)
                });
            }
            CordovaSdk.Geolocation = function (Callback) {
                navigator.geolocation.getCurrentPosition(function (position) {
                    Callback(null, position)
                }, function (error) {
                    Callback(error)
                });
            }


            CordovaSdk.Device = function (Callback) {
                Callback(window.device)
            }





            // onSuccess: Get a snapshot of the current acceleration
            //
            CordovaSdk.Accelerometer = function (Callback) {
                navigator.accelerometer.getCurrentAcceleration(function (acceleration) {
                    Callback(null, acceleration)
                }, function (error) {
                    Callback(error)
                });
            }



            // onError: Failed to get the acceleration
            //




            CordovaSdk.Connection = function (Callback) {
                var networkState = navigator.connection.type;
                var states = {};
                states[Connection.UNKNOWN] = 'Unknown connection';
                states[Connection.ETHERNET] = 'Ethernet connection';
                states[Connection.WIFI] = 'WiFi connection';
                states[Connection.CELL_2G] = 'Cell 2G connection';
                states[Connection.CELL_3G] = 'Cell 3G connection';
                states[Connection.CELL_4G] = 'Cell 4G connection';
                states[Connection.CELL] = 'Cell generic connection';
                states[Connection.NONE] = 'No network connection';

                Callback({
                    name: states[networkState],
                    type: networkState
                });

            };


            CordovaSdk.capturePhoto = function (Callback) {
                // Take picture using device camera and retrieve image as base64-encoded string
                navigator.camera.getPicture(function (url) {
                    Callback(null, url)
                }, Callback, {
                    quality: 50,
                    destinationType: destinationType.DATA_URL
                });
            }

            // A button will call this function
            //
            CordovaSdk.capturePhotoEdit = function (Callback) {
                // Take picture using device camera, allow edit, and retrieve image as base64-encoded string
                navigator.camera.getPicture(function (url) {

                    Callback(null, url)

                }, Callback, {
                    quality: 20,
                    allowEdit: true,
                    destinationType: destinationType.DATA_URL
                });
            }

            // A button will call this function
            //
            CordovaSdk.getLibraryPhoto = function (Callback) {
                // Retrieve image file location from specified source
                navigator.camera.getPicture(function (url) {
                    Callback(null, url)
                }, Callback, {
                    quality: 50,
                    destinationType: destinationType.FILE_URI,
                    sourceType: pictureSource.PHOTOLIBRARY
                });
            }
            CordovaSdk.getAlbumPhoto = function (Callback) {
                // Retrieve image file location from specified source
                navigator.camera.getPicture(function (url) {

                    Callback(null, url)

                }, Callback, {
                    quality: 50,
                    destinationType: destinationType.FILE_URI,
                    sourceType: pictureSource.SAVEDPHOTOALBUM
                });
            }
            var pictureSource, destinationType;
            if (navigator && navigator.camera) {

                pictureSource = navigator.camera.PictureSourceType;
                destinationType = navigator.camera.DestinationType;
            }

        }

        var _Compass = function (CordovaSdk) {

            // The watch id references the current `watchHeading`
            var watchID = null;


            CordovaSdk.Watch = function (ev) {
                if (watchID == null) {
                    ev.innerHTML = 'Stop';
                    startWatch()
                } else {
                    ev.innerHTML = 'Start';
                    stopWatch()
                }
            }
            var startWatch = function (ev) {



                // Update compass every 3 seconds
                var options = {
                    frequency: 3000
                };

                watchID = navigator.compass.watchHeading(onSuccess, onError, options);


            };
            CordovaSdk.startWatch = startWatch;
            // Stop watching the compass
            //
            var stopWatch = function () {
                if (watchID) {
                    navigator.compass.clearWatch(watchID);
                    watchID = null;
                }
            }
            CordovaSdk.stopWatch = stopWatch;

            // onSuccess: Get the current heading
            //
            function onSuccess(heading) {
                var element = document.getElementById('heading');
                element.innerHTML = 'Heading: ' + heading.magneticHeading;
            }

            // onError: Failed to get the heading
            //
            function onError(compassError) {
                Alert('Compass error: ' + compassError.code);
            }

        }




        var initjssdk = function (CordovaSdk) {
            for (var key in CordovaSdk) {
                if (jssdk[key] == null) {
                    new DefineProperty(jssdk, key, CordovaSdk[key])
                }
                if (self[key] == null) {
                    new DefineProperty(self, key, CordovaSdk[key])
                }
            }
        }
        ///http://www.phonegap100.com/doc/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser\\



        function deviceready() {
            var CordovaSdk = {};
            new _chcp(CordovaSdk);
            new _dialogs(CordovaSdk);
            new _file(CordovaSdk);
            new _Compass(CordovaSdk);
            new _Events(CordovaSdk);
            new _initcordova(CordovaSdk);
            new _Device(CordovaSdk);
            new _webapp(CordovaSdk);
            new initjssdk(CordovaSdk)

            UploadSys(CordovaSdk);
        }
        document.addEventListener("deviceready", function () {

            deviceready();

        }, false);
        var self = this;
    };

    module.exports = SDK;